<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: wangzm
 * @LastEditTime: 2020-03-10 15:07:36
 * @description: file content
 -->
<template>
  <base-page-view class-name="page-container rule-main">
    <!--#ifdef MP-WEIXIN-->
    <rich-text :nodes="nodes" style="line-height: 50rpx;font-size:30rpx;"></rich-text>
    <!--#endif-->
    <!--#ifdef H5-->
    <view v-html="htmlContent"></view>
    <!--#endif-->
  </base-page-view>
</template>

<script>
import { parseHtmlSync } from '@/components/jyf-Parser/libs/MpHtmlParser'
import './index.scss'
export default {
  components: {
  },
  props: {
    type: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      plaformType: '',
      nodes: [],
      htmlContent: '',
      title: '',
      bxTypeObj: {
        userAgreement: { key: 'user_agreement', title: '用户协议' },
        userPrivacy: { key: 'private_agreement', title: '隐私协议' },
        guidance: { key: 'novice_guidance', title: '新手引导' },
        aboutUs: { key: 'about_us', title: '关于我们' },
        ruleBox: { key: 'box', title: '箱起规则' },
        ruleLaw: { key: 'e_commerce_law', title: '新电商法' },
        wechatHelp: { key: 'wechat_help', title: '微信二维码帮助' },
        // storePartnerAgreement: '', // 碧选优品协议
        intro: { key: 'about_us', title: '碧选简介' },
        serviceContract: { key: 'user_agreement', title: '服务协议' },
        certificates: { key: 'e_commerce_law', title: '平台证照' },
        privateAgreement: { key: 'private_agreement', title: '隐私政策' }
      },
      bxZbTypeObj: {
        intro: { key: 'about_us', title: '碧选直播简介' },
        serviceContract: { key: 'service_agreement', title: '服务协议' },
        privateAgreement: { key: 'private_agreement', title: '隐私政策' }
      }
    }
  },
  onLoad(options) {
    this.plaformType = options.plaform || 'bx'
    const type = options.type || this.type
    if (type) {
      this.initData(type)
    }
  },
  methods: {
    async initData(type) {
      let res = null
      let key = ''
      let title = ''
      if (this.plaformType === 'bx') {
        key = this.bxTypeObj[type] ? this.bxTypeObj[type].key : type
        title = this.bxTypeObj[type] ? this.bxTypeObj[type].title : ''
        res = await this.$api.mineApi.getAgreementDetail({ key })
      } else {
        key = this.bxZbTypeObj[type].key || type
        title = this.bxZbTypeObj[type] ? this.bxZbTypeObj[type].title : ''
        res = await this.$api.mineApi.getBXZBHelp(key)
      }
      if (res.success && res.data) {
        const { content, value, name } = res.data
        this.htmlContent = content || value
        if (this.htmlContent) {
          this.nodes = parseHtmlSync(this.htmlContent.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;" '))
        } else {
          this.nodes = []
        }
        this.$setNavTitle(title || name)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.rule-title {
  color: #000;
  font-weight: bold;
  text-align: center;
  padding: 30rpx 0 0;
  font-size: 36rpx;
  background-color: #fff;;
}
</style>
